package com.aust.state;

/**
 * 模拟网络延时：
 * 放大问题的发生性
 */
public class TestSleep implements Runnable {

    // 票数
    private int ticketNums = 10;

    @Override
    public void run() {
        while (ticketNums >= 0) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "拿到了第" + ticketNums-- + "张票");
        }
    }

    public static void main(String[] args) {
        TestSleep testSleep = new TestSleep();
        /**
         * 线程不安全
         */
        new Thread(testSleep, "小明").start();
        new Thread(testSleep, "黄牛").start();
        new Thread(testSleep, "老师").start();
    }

}
